|
|
|
|
|
|
|
equation for the X coordinate of the curve is given by X(t) = ax * t3 + bx * t2 + cx * t + dx, the endpoint conditions require that: |
|
|
|
 |
|
|
|
|
X(0) = Ex1 = ax * 03 + bx * 02+ cx * 0 + dx = dx X(1) = Ex2 = ax * 13 + bx * 12+ cx * 1 + dx = ax = bx + cx + dx |
|
|
|
|
|
|
|
|
At the endpoints, the X component of the tangent vectors should match the derivative of X(t). The derivative of X(t) is X'(t) = 3 * ax * t2 + 2 * bx * t + cx so the tangent conditions require: |
|
|
|
 |
|
|
|
|
X' (0) = Vx1 = 3 * ax * 02 + 2 * bx * 0 + cx = cx X' (1) = Vx2 = 3 * ax * 12 + 2 * bx * 1 + cx = 3 * ax + 2 * bx + cx |
|
|
|
|
|
|
|
|
Using these four equations defined by the endpoint and tangent conditions, you can solve for the constants ax, bx, cx, and dx to get: |
|
|
|
 |
|
|
|
|
ax = Vx2 + Vx1 - 2 * Ex2 + 2 * Ex1 bx = 3 * Ex2 - 2 * Vx1 - 3 * Ex1 - Vx2 cx = Vx1 dx = Ex1 |
|
|
|
|
|
|
|
|
Similar equations hold for the Y components of the endpoints and tangent vectors. |
|
|
|
|
|
|
|
|
With these equations, you can write a GetHermiteValues subroutine in Visual Basic to compute the parameters you need to draw the Hermite curve. The parameter declarations are longer than the calculations themselves. |
|
|
|
 |
|
|
|
|
' Compute the Hermite curve parameters. Private Sub GetHermiteValues( _
ByVal ex1 As Single, ByVal ey1 As Single, _
ByVal ex2 As Single, ByVal ey2 As Single, _
ByVal vx1 As Single, ByVal vy1 As Single, _
ByVal vx2 As Single, ByVal vy2 As Single, _
ByRef Ax As Single, ByRef Bx As Single, _
ByRef Cx As Single, ByRef Dx As Single, _
ByRef Ay As Single, ByRef By As Single, _
ByRef Cy As Single, ByRef Dy As Single)
Ax = vx2 + vx1 - 2 * ex2 + 2 * ex1
Bx = 3 * ex2 - 2 * vx1 - 3 * ex1 - vx2
Cx = vx1
Dx = ex1
Ay = vy2 + vy1 - 2 * ey2 + 2 * ey1
By = 3 * ey2 - 2 * vy1 - 3 * ey1 - vy2
Cy = vy1
Dy = ey1
End Sub |
|
|
|
|
|